package com.yfwj.sdr;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.yanfeiwuji.web.query.BaseQuery;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@MapperScan("com.yfwj.sdr")
public class SdrApplication {

  public static void main(String[] args) {
    SpringApplication.run(SdrApplication.class, args);
  }

  @Autowired
  SysUserRepo sysUserRepo;

//  @Bean
//  ObjToPacking<R> objToPacking() {
//    return o -> new R("success", "success", o);
//  }

  @Bean
  @ConditionalOnMissingBean
  public MybatisPlusInterceptor paginationInterceptor( ) {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
  }

  @GetMapping("/")
  public Page<SysUser> as(BaseQuery<SysUser> query) {
    return  sysUserRepo.selectPage(query.page(),query.query());
  }

}
